<include file="public/header" title="填写订单" body="g4"/>
<include file="public/header_nav" title="填写订单" href="javascript:history.back(-1);"/>
<div id="wrapBody">
    <div id="pagePay">
        <form name="cart2_form" id="cart2_form" method="post">
            <input type="hidden" value="{$pre_sell_price['goods_num']}" name="goods_num">
            <input type="hidden" value="{$pre_sell_info['act_id']}" name="act_id">
            <input type="hidden" id="wap_invoice_title" name="invoice_title" value="">
            <input type="hidden" id="wap_taxpayer" name="taxpayer" value="">
            <input type="hidden" name="address_id" value="" autocomplete="off"/> <!--收货地址id-->
        </form>
        <!--地址-s-->
            <div class="edit_gtfix" id="addressDefault">
                <div class="namephone fl">
                    <div class="top">
                        <div class="le fl" id="default_address_consignee"></div>
                        <div class="lr fl" id="default_address_mobile"></div>
                    </div>
                    <div class="bot">
                        <i class="dwgp"></i>
                        <span id="default_address_text"></span>
                    </div>
                </div>
                <div class="fr youjter">
                    <i class="Mright"></i>
                </div>
                <div class="ttrebu">
                    <img src="__STATIC__/images/tt.png"/>
                </div>
            </div>
        <!--地址-e-->

        <!--商品信息-s-->
                <div class="ord_list fill-orderlist p">
                    <div class="maleri30">
                            <div class="shopprice">
                                <div class="img_or fl">
                                    <img src="{$pre_sell_info[goods_id]|goods_thum_images=100,100}"/>
                                </div>
                                <div class="fon_or fl">
                                    <h2 class="similar-product-text">{$pre_sell_info['act_name']}</h2>
                                    <div>{$pre_sell_info[spec_key_name]}</div>
                                </div>
                                <div class="price_or fr">
                                    <p class="red"><if condition="$pre_sell_price['deposit_price'] gt 0">订金（元）<else/>单价（元）</if><span>￥</span>
                                    <span><if condition="$pre_sell_price['deposit_price'] gt 0">{$pre_sell_price['deposit_price']}<else/>{$pre_sell_price['cut_price']}</if></span></p>
                                    <p class="ligfill">x{$pre_sell_price.goods_num}</p>
                                </div>
                            </div>
                    </div>
                </div>
        <!--商品信息-e-->
        <!--支持配送,发票信息-s-->
            <div class="information_dr">
                <div class="maleri30">
                    <div class="information_dr">
                            <div class="invoice list7">
                                <div class="myorder p">
                                    <div class="content30">
                                        <a class="invoiceclickin" href="javascript:void(0)">
                                            <div class="order">
                                                <div class="fl">
                                                    <span>发票信息</span>
                                                </div>
                                                <div class="fr">
                                                    <span class="invoice_title" style="margin-top: 0.6rem;">不开发票</span>
                                                    <i class="Mright"></i>
                                                </div>
                                            </div>
                                        </a>
                                    </div>
                                </div>
                            </div>
                            <div id="invoice" class="invoice list7" style="display: none;">
                                <div class="myorder p">
                                    <div class="content30">
                                        <div class="incorise" id="invoice_radio_title">
                                            <span>发票抬头：</span>
                                            <div class="myorder radios-choice-h">
                                                <div class="incorise">
                                                    <label><input type="radio" class="alonestyle" value="个人" name="radio_title"
                                                                  data="geren" id="geren">个人</label>
                                                    <label><input type="radio" class="alonestyle" value="单位" name="radio_title"
                                                                  data="danwei" id="danwei">单位</label>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="myorder p" id="monad">
                                    <div class="incorise">
                                        <input type="text" id="invoice_title" value="" maxlength="30" placeholder="请填写单位名称"/>
                                        <input type="text" id="taxpayer" value="" maxlength="20" placeholder="请在此填写纳税人识别号"/>
                                    </div>
                                    <span style="display: block; color:red;font-size:.512rem;line-height: .64rem; ">开企业抬头发票，请准确填写对应的“纳税人识别号”，以免影响您的发票报销.</span>
                                </div>
                                <div class="myorder p">
                                    <div class="content30">
                                        <div class="incorise">
                                            <span>发票内容：</span>
                                            <div class="myorder radios-choice-h" id="noincorise">
                                                <div class="incorise">
                                                    <label><input type="radio" class="alonestyle" value="不开发票" name="radio_cont"
                                                                  data="noincorise" id="noincorises">不开发票</label>
                                                    <label><input type="radio" class="alonestyle" value="明细" name="radio_cont"
                                                                  data="detail" id="detail">明细</label>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="myorder p">
                                    <div class="content30">
                                        <div class="incorise">
                                            <div class="myorder p">
                                                <div class="content30">
                                                    <div class="incorise">
                                                        <a href="javascript:void(0)" onclick="save_invoice()"
                                                           class="submits_de bagrr phoneclck">确认</a>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <!--使用余额、积分-e-->
                    </div>
                </div>
            </div>
        <!--支持配送,发票信息-e-->
        <!--订单金额-s-->
            <div class="information_dr ma-to-20">
                <div class="maleri30">
                    <div class="xx-list">
                        <p class="p">
                            <span class="fl">商品金额：</span>
                            <span class="fr red"><span>￥</span><span><if condition="$pre_sell_price['deposit_price'] gt 0">{$pre_sell_price['deposit_price']*$pre_sell_price['goods_num']}<else/>{$pre_sell_price['cut_price']*$pre_sell_price['goods_num']}</if></span>元</span>
                        </p>
                    </div>
                </div>
            </div>
        <!--订单金额-e-->

        <!--提交订单-s-->
            <div class="mask-filter-div" style="display: none;"></div>
            <div class="payit fillpay ma-to-200">
                <div class="fr">
                    <a href="javascript:void(0)" onclick="submit_order()">提交订单</a>
                </div>
                <div class="fl">
                    <p><span class="pmo">应付金额：</span>￥<span id="payables"><if condition="$pre_sell_price['deposit_price'] gt 0">{$pre_sell_price['deposit_price']*$pre_sell_price['goods_num']}<else/>{$pre_sell_price['cut_price']*$pre_sell_price['goods_num']}</if></span><span></span></p>
                </div>
            </div>
        <!--提交订单-e-->
    </div>
<!--地址管理-->
    <div id="addressList" style="display: none">
        <!--地址-s-->
        <div class="dizhi-pop">
            <div class="z-Package-hrader">
                <i class="z-Package-icon Package-icon-close" id="address_list_back"></i>
                <h5>选择地址</h5>
            </div>
            <div id="address_list_html"></div>
            <!--地址-e-->
            <div class="createnew ">
                <a id="add_address">+新建地址</a>
            </div>
        </div>
    </div>
    <div id="addressAdd" style="display: none">
        <div class="dizhi-pop">
            <div class="z-Package-hrader">
                <i class="z-Package-icon Package-icon-close" id="address_add_back"></i>
                <h5>新建/编辑地址</h5>
            </div>
            <div class="floor my p edit">
                <form id="address_form">
                    <input type="hidden" value="" name="address_id"/>
                    <input type="hidden" value="" name="province"/>
                    <input type="hidden" value="" name="city"/>
                    <input type="hidden" value="" name="district"/>

                    <div class="content">
                        <div class="floor list7">
                            <div class="myorder p">
                                <div class="content30">
                                    <a href="javascript:void(0)">
                                        <div class="order">
                                            <div class="fl">
                                                <span>收货人:</span>
                                            </div>
                                            <div class="fl">
                                                <input type="text" value="" name="consignee"/>
                                                <span class="err" id="err_address_consignee"></span>
                                            </div>
                                        </div>
                                    </a>
                                </div>
                            </div>
                            <div class="myorder p">
                                <div class="content30">
                                    <a href="javascript:void(0)">
                                        <div class="order">
                                            <div class="fl">
                                                <span>手机号码:</span>
                                            </div>
                                            <div class="fl">
                                                <input type="tel" value="" name="mobile" onkeyup="this.value=this.value.replace(/[^\d]/g,'')"/>
                                            </div>
                                        </div>
                                    </a>
                                </div>
                            </div>
                            <div class="myorder p">
                                <div class="content30">
                                    <a href="javascript:void(0)" onclick="location_address(this);">
                                        <div class="order">
                                            <div class="fl">
                                                <span>所在地区: </span>
                                            </div>
                                            <div class="fl">
                                                <span id="area"></span>
                                            </div>
                                            <div class="fr">
                                                <i class="Mright"></i>
                                            </div>
                                        </div>
                                    </a>
                                </div>
                            </div>
                            <div class="myorder p">
                                <div class="content30">
                                    <a href="javascript:void(0)">
                                        <div class="order">
                                            <div class="fl">
                                                <span>详细地址:</span>
                                            </div>
                                            <div class="fl">
                                                <input type="text" value="{$address.address}" name="address"/>
                                            </div>
                                        </div>
                                    </a>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="createnew ">
                        <a id="address_form_confirm">确认</a>
                    </div>
                </form>
            </div>
            <!--选择地区-s-->
            <div class="container">
                <div class="city">
                    <div class="screen_wi_loc">
                        <div class="classreturn loginsignup">
                            <div class="content">
                                <div class="ds-in-bl return seac_retu">
                                    <a href="javascript:void(0);" onclick="close_location();"><img src="__STATIC__/images/return.png" alt="返回"></a>
                                </div>
                                <div class="ds-in-bl search center">
                                    <span class="sx_jsxz">选择地区</span>
                                </div>
                                <div class="ds-in-bl suce_ok">
                                    <a href="javascript:void(0);">&nbsp;</a>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="province-list"></div>
                    <div class="city-list" style="display:none"></div>
                    <div class="area-list" style="display:none"></div>
                </div>
            </div>
            <!--选择地区-e-->
        </div>
        <script src="__STATIC__/js/mobile-location.js"></script>
        <script>
            //选择地址回调
            var address_form = $('#address_form');
            function select_area_callback(province_name, city_name, district_name, province_id, city_id, district_id) {
                var area = province_name + ' ' + city_name + ' ' + district_name;
                $("#area").text(area);
                address_form.find("input[name='province']").val(getCookie('province_id'));
                address_form.find("input[name='city']").val(getCookie('city_id'));
                address_form.find("input[name='district']").val(getCookie('district_id'));
            }
        </script>
    </div>
</div>

<script type="text/javascript">
    window.addEventListener('popstate', function () {
        panel();
    });
    var cart2_form = $('#cart2_form');
    $(document).ready(function () {
        get_invoice();
        get_address_list();
    });
    //各种弹窗返回上一步
    $(function () {
        //主页面返回上一步
        $(document).on('click', '#back', function () {
            var action = cart2_form.find("input[name='action']");
            var url = "/index.php?m=Mobile&c=Cart&a=index";
            if (action.val() == 'buy_now') {
                var goods_id = cart2_form.find("input[name='goods_id']");
                var item_id = cart2_form.find("input[name='item_id']");
                url = "/index.php?m=Mobile&c=Goods&a=goodsInfo&id="+goods_id.val()+'&item_id='+item_id.val();
            }
            window.location.href = url;
        });
        //地址弹窗返回上一步
        $(document).on('click', '#address_list_back,#address_add_back,#shop_list_back,#shop_consignee_back,#map_back', function () {
            history.back(-1);
            panel();
        });
    })
    //点击地址
    $(function () {
        //点击地址
        $(document).on('click', '#addressDefault', function () {
            window.location.hash = "#addressList";
            get_address_list();
            panel();
        });
        //选择地址
        $(document).on('click', '.select_address', function () {
            var address_id = $(this).data('address-id');
            var mobile = $(this).data('mobile');
            var consignee = $(this).data('consignee');
            var address_area = $(this).data('address-area');
            var address = $(this).data('address');
            var province_id = $(this).data('province-id');
            var city_id = $(this).data('city-id');
            var district_id = $(this).data('district-id');
            var longitude = $(this).data('longitude');
            var latitude = $(this).data('latitude');
            cart2_form.find("input[name='address_id']").val(address_id);
            $("#default_address_mobile").empty().html(mobile);
            $("#default_address_consignee").empty().html(consignee);
            $("#default_address_text").empty().html(address_area + ' '+ address);
            window.location.hash = "#";
            panel();
            get_shop_list(province_id, city_id, district_id, '', longitude, latitude);
        });
        //点击新建地址
        $(document).on('click', '#add_address', function () {
            address_form.find("input[name='address_id']").val('');
            address_form.find("input[name='consignee']").val('');
            address_form.find("input[name='address']").val('');
            address_form.find("input[name='mobile']").val('');
            address_form.find("input[name='province']").val('');
            address_form.find("input[name='city']").val('');
            address_form.find("input[name='district']").val('');
            $('#area').html('');
            window.location.hash = "#addressAdd";
            panel();
        });
        //添加地址
        $(document).on('click', '#address_form_confirm', function () {
            $.ajax({
                type: "POST",
                url: '/index.php?m=Mobile&c=User&a=addressSave',
                data:  $("#address_form").serialize(),
                dataType: "json",
                success: function (data) {
                    if (data.status == 1) {
                        $("#address_add_back").trigger('click');
                        get_address_list(data.result.address_id);
                    } else {
                        var err_msg = data.msg;
                        $.each(data.result, function (index, item) {
                            err_msg = item;
                        });
                        layer.open({icon: 2, content: err_msg, time: 2});
                    }
                }
            });
        });
        //编辑地址弹窗事件
        $(document).on("click", '.address_item', function (e) {
            window.location.hash = "#addressAdd";
            panel();
            var select_address = $(this).parent().parent().find('.select_address');
            address_form.find("input[name='address_id']").val(select_address.data('address-id'));
            address_form.find("input[name='consignee']").val(select_address.data('consignee'));
            address_form.find("input[name='address']").val(select_address.data('address'));
            address_form.find("input[name='mobile']").val(select_address.data('mobile'));
            address_form.find("input[name='province']").val(select_address.data('province-id'));
            address_form.find("input[name='city']").val(select_address.data('city-id'));
            address_form.find("input[name='district']").val(select_address.data('district-id'));
            $('#area').html(select_address.data('address-area'));
        })
    })
    //单页面显示
    function panel(){
        var hash = window.location.hash;
        $('#wrapBody').children('div').hide();
        if(hash == ''){
            $('#pagePay').show();
        }else{
            $(hash).show();
        }
    }
    //获取自提点列表
    function get_shop_list(province_id, city_id, district_id, shop_address, longitude, latitude) {
        $.ajax({
            type: "POST",
            url: "{:U('Home/Api/shop')}",
            dataType: 'json',
            data: {
                province_id: province_id,
                city_id: city_id,
                district_id: district_id,
                shop_address: shop_address,
                longitude: longitude,
                latitude: latitude
            },
            success: function (data) {
                if(data.length > 0){
                    $('#door_to_door_div').show();
                    set_shop_list(data);
                }else{
                    $('#door_to_door_div').hide();
                }
            }
        });
    }
    //自提点初始化
    function set_shop_list(shop_list_data) {
        var shop_html = '';
        for (var i = 0; i < shop_list_data.length; i++) {
            shop_html += '<li class="p" data-shop-id="'+shop_list_data[i].shop_id+'" data-longitude="'+shop_list_data[i].longitude+'" data-latitude="'+shop_list_data[i].latitude+'"' +
                    ' data-shop-address="'+shop_list_data[i].shop_address+'" data-phone="'+shop_list_data[i].phone+'" data-work-day="'+shop_list_data[i].work_day+'" ' +
                    'data-work-time="'+shop_list_data[i].work_time+'"> <div class="fl Package-radio-wrap"> <div class="Package-radio"> ' +
                    '<label class="Package-radio-label"></label> </div> </div> <div class="fl Package-radio-cont"> <div class="z-SelectPackage-title">' +
                    shop_list_data[i].shop_name + '</div> <div class="z-SelectPackage-nvg"><span>'+shop_list_data[i].shop_address+'</span></div> ' +
                    '<div class="z-SelectPackage-phon">电话:<em>' + shop_list_data[i].phone + '</em></div> </div> ' +
                    '<div class="fl Package-radio-Lately p"> <i class="Package-Lately  fl"> 离我最近 </i> <div class="Package-distance-wrap fl">' +
                    ' <div class="Package-distance">' + shop_list_data[i].distance_text + '</div> <div class="p distance-icon-wrap"> <div class="Package-distance-icon fl"> ' +
                    '</div> <span class="Package-Location fl"></span> </div> </div> </div> </li>';
        }
        $("#shop_list").empty().append(shop_html);
    }
    //自提点初始化数据
    function initShopInfo() {
        var consignee = cart2_form.find("input[name='consignee']");
        var mobile = cart2_form.find("input[name='mobile']");
        if(consignee.val() == ''){
            var consignee_val = $('#default_address_consignee').html();
            consignee.val(consignee_val);
        }
        if(mobile.val() == ''){
            var mobile_val = $('#default_address_mobile').html();
            mobile.val(mobile_val);
        }
        $('#consignee_txt').html(consignee.val());
        $('#mobile_txt').html(mobile.val());
        $('#mobile').val(mobile.val());
        $('#consignee').val(consignee.val());
        var shop_item = $('.Package-radio-checked').parent().parent().parent();
        $('#shop_address').html(shop_item.find('.z-SelectPackage-title').html());
    }
    //选择上门自提时，初始化自提点
    function initShop() {
        var shop_list = $("#shop_list");
        if(shop_list.find('Package-radio-checked').length == 0){
            shop_list.children('li').eq(0).find(".Package-radio label").trigger('click');
        }
        $('#shop_list_confirm').trigger('click');
    }
    //获取地址列表
    function get_address_list(select_address_id){
        var address_id = cart2_form.find("input[name='address_id']");
        $.ajax({
            type: "get",
            url: '/index.php?m=Mobile&c=User&a=ajaxAddressList',
            dataType: "json",
            success: function (data) {
                var address_list_html = '';
                for (var i = 0; i < data.length; i++) {
                    address_list_html += '<div class="jd_listaddless p "> <div class="maleri30"> <a class="select_address address_id_'+data[i].address_id+'" ' +
                            'data-address-id="'+data[i].address_id+'" data-mobile="'+ data[i].mobile +'" data-consignee="'+ data[i].consignee+'" ' +
                            'data-address-area="'+ data[i].address_area+'" data-address="'+ data[i].address+'" data-province-id="'+data[i].province+'"  ' +
                            'data-city-id="'+data[i].city+'" data-district-id="'+data[i].district+'" data-town-id="'+data[i].twon+'" data-longitude="'+data[i].longitude+'" ' +
                            'data-latitude="'+data[i].latitude+'"  > <div class="name fl"> <h1>'+data[i].consignee+'</h1> </div> <div class="numberaddress fl"> ' +
                            '<span class="number">电话：'+ data[i].mobile +'</span> <span class="similars">' + data[i].address_area + ' ' + data[i].address +'</span> ' +
                            '</div> </a> <div class="editdiv fl"> <a class="address_item"> <i class="eedit"></i> </a> </div> </div> </div>';
                }
                $("#address_list_html").empty().html(address_list_html);
                if(data.length == 0){
                    $("#add_address").trigger('click');
                }
                if(data.length > 0 && address_id.val() == ''){
                    $("#address_list_html").find('.select_address').eq(0).trigger('click');
                }
                if(select_address_id > 0){
                    $("#address_list_html").find('.address_id_'+select_address_id).trigger('click');
                }
            }
        });
    }
    function location_address(e){
        $('.container').animate({width: '14.4rem', opacity: 'show'}, 'normal',function(){
            $('.container').show();
        });
        if(!$('.container').is(":hidden")){
            $('body').css('overflow','hidden')
            cover();
            $('.mask-filter-div').css('z-index','9999');
        }
    }

/*******发票*******/
    function toogle(id) {
        condition = $(id).attr('data');
        //个人
        if (condition == 'geren') {
            $('#wap_invoice_title').val("个人");
            $('#monad').hide();
        }
        //单位
        if (condition == 'danwei') {
            invoice_title = $('#invoice_title').val();
            $('#wap_invoice_title').val(invoice_title);
            $('#monad').show();
        }

        invoice_title = $(id).find('input').attr('value');
        //不开发票
        if (condition == 'noincorise') {
            $('#wap_invoice_title').val("");
            //                $('#monad,#invoice').hide();
            //                $(".invoice_title").html("不开发票");
        }
        $("input[type='radio']").each(function () {
            if ($(this).is(":checked")) {
                if ($(this).val() == "个人") {
                    invoice_title = "个人";
                    taxpayer = "";
                    str = "个人";
                }
                if ($(this).val() == '不开发票') {
                    invoice_title = "";
                    taxpayer = "";
                    invoice_desc = '不开发票';
                    str = "不开发票";
                    $('#monad').hide();
                }
                if ($(this).val() == "单位") {
                    invoice_title = $("#invoice_title").val();
                    taxpayer = $("#taxpayer").val();
                    $('#monad').show();
                    str = "单位";
                }
                if ($(this).val() == '明细') {
                    invoice_desc = "明细";
                }
            }
        });
        if ($("#detail").is(":checked")) {
            str += " - 明细";
        }
        if (str == "不开发票") {
            $('#wap_invoice_title').val("");
            $(".invoice_title").html(str);
        } else {
            $('#wap_invoice_title').val(invoice_title);
            $(".invoice_title").html("纸质（" + str + "）");
        }
    }
    $(document).on("click", "input[type='radio']", function () {
        toogle(this);
    });
    // 校验组织机构代码
    function orgcodevalidate(value) {
        if (value != "") {
            var part1 = value.substring(0, 8);
            var part2 = value.substring(value.length - 1, 1);
            var ws = [3, 7, 9, 10, 5, 8, 4, 2];
            var str = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
            var reg = /^([0-9A-Z]){8}$/;
            if (!reg.test(part1)) {
                return true
            }
            var sum = 0;
            for (var i = 0; i < 8; i++) {
                sum += str.indexOf(part1.charAt(i)) * ws[i];
            }
            var C9 = 11 - (sum % 11);
            var YC9 = part2 + '';
            if (C9 == 11) {
                C9 = '0';
            } else if (C9 == 10) {
                C9 = 'X';
            } else {
                C9 = C9 + '';
            }
            return YC9 != C9;
        }
    }
    // 校验地址码
    function checkAddressCode(addressCode) {
        var provinceAndCitys = {
            11: "北京",
            12: "天津",
            13: "河北",
            14: "山西",
            15: "内蒙古",
            21: "辽宁",
            22: "吉林",
            23: "黑龙江",
            31: "上海",
            32: "江苏",
            33: "浙江",
            34: "安徽",
            35: "福建",
            36: "江西",
            37: "山东",
            41: "河南",
            42: "湖北",
            43: "湖南",
            44: "广东",
            45: "广西",
            46: "海南",
            50: "重庆",
            51: "四川",
            52: "贵州",
            53: "云南",
            54: "西藏",
            61: "陕西",
            62: "甘肃",
            63: "青海",
            64: "宁夏",
            65: "新疆",
            71: "台湾",
            81: "香港",
            82: "澳门",
            91: "国外"
        };
        var check = /^[1-9]\d{5}$/.test(addressCode);
        if (!check) return false;
        if (provinceAndCitys[parseInt(addressCode.substring(0, 2))]) {
            return true;
        } else {
            return false;
        }
    }
    function save_invoice() {
        var str = "";
        var invoice_title;
        var taxpayer;
        var invoice_desc;
        var res = "y";
        $("input[type='radio']").each(function () {
            if ($(this).is(":checked")) {
                if ($(this).val() == "个人") {
                    invoice_title = "个人";
                    taxpayer = "";
                    str = "个人";
                }
                if ($(this).val() == '不开发票') {
                    invoice_title = "个人";
                    taxpayer = "";
                    invoice_desc = '不开发票';
                    str = "不开发票";
                }
                if ($(this).val() == "单位") {
                    if (!$("#noincorises").is(":checked")) {
                        if ($("#invoice_title").val() == "") {
                            layer.open({content: '请输入单位名称', time: 2});
                            res = "n";
                            return false;
                        }
                        taxpayer = $("#taxpayer").val();
                        //                                    if (taxpayer != "") {
                        if ((taxpayer.length == 15) || (taxpayer.length == 18) || (taxpayer.length == 20)) {
                        } else {
                            layer.open({content: "请输入正确的纳税人识别号！(核对位数)", time: 2});
                            res = "n";
                            return false;
                        }
                        var addressCode = taxpayer.substring(0, 6);
                        // 校验地址码
                        var check = checkAddressCode(addressCode);
                        if (!check) {
                            layer.open({content: "请输入正确的纳税人识别号(地址码)！", time: 2});
                            res = "n";
                            return false;
                        }
                        // 校验组织机构代码
                        var orgCode = taxpayer.substring(6, 9);
                        check = orgcodevalidate(orgCode);
                        if (!check) {
                            layer.open({content: "请输入正确的纳税人识别号(组织机构代码) ！", time: 2});
                            res = "n";
                            return false;
                        }
                        $('#wap_taxpayer').val(taxpayer);
                        //                                    }
                        invoice_title = $("#invoice_title").val();
                        taxpayer = $("#taxpayer").val();
                        str = $("#invoice_title").val();
                    }
                }
                if ($(this).val() == '明细') {
                    invoice_desc = "明细";
                }
            }
        });
        if ($("#detail").is(":checked")) {
            str += " - 明细";
        }
        if (str == "不开发票") {
            $('#wap_invoice_title').val("");
            $('#wap_taxpayer').val("");
            $(".invoice_title").html(str);
        } else {
            $('#wap_taxpayer').val(taxpayer);
            $('#wap_invoice_title').val(invoice_title);
            $(".invoice_title").html("纸质（" + str + "）");
        }

        if (res != "n") {
            var data = {invoice_title: invoice_title, taxpayer: taxpayer, invoice_desc: invoice_desc};
            $.post("{:U('Cart/save_invoice')}", data, function (json) {
                var data = eval("(" + json + ")");

                $("#invoice").hide()
            });
        }

    }
    function get_invoice() {
        var str = "";
        $.get("{:U('Cart/invoice')}", function (json) {
            var data = eval("(" + json + ")");
            if (data.status > 0) {

                if (data.result.invoice_title == "") {
                    $('#monad').hide();

                } else {
                    $('#wap_invoice_title').val(data.result.invoice_title);
                    $('#wap_taxpayer').val(data.result.taxpayer);
                    $('#invoice_title').val(data.result.invoice_title);
                    $("#invoice_desc").val(data.result.invoice_desc);
                    $("#taxpayer").val(data.result.taxpayer);
                    str = "纸质（" + data.result.invoice_title + "-明细）";
                    $("#danwei").attr("checked", "checked");
                }
                if (data.result.invoice_title == "个人") {
                    $('#wap_invoice_title').val("个人");
                    $('#wap_taxpayer').val("");
                    $("#geren").attr("checked", "checked");
                    $('#invoice_title').val("");
                    $("#invoice_desc").val("");
                    $("#taxpayer").val("");
                    $('#monad').hide();
                    $(".invoice_title").html("纸质（个人-明细）");
                    str = "纸质（个人-明细）";
                }
                if (data.result.invoice_desc == "不开发票") {
                    $('#wap_invoice_title').val("");
                    $('#wap_taxpayer').val("");
                    $('#invoice_title').val("");
                    $("#invoice_desc").val(data.result.invoice_desc);
                    $("#taxpayer").val("");
                    $("#noincorises").attr("checked", "checked");
                    str = "不开发票";
                } else {
                    //                        $('#monad,#invoice').show();
                    $("#detail").attr("checked", "checked");
                }
                $(".invoice_title").html(str);

            } else {
                $("#geren").attr("checked", "checked");
                $('#monad').hide();
                $("#noincorises").attr("checked", "checked");
            }
        });
    }


/********提交订单********/
    var ajax_return_status = 1; // 标识ajax 请求是否已经回来 可以进行下一次请求
    function submit_order() {
        if (ajax_return_status == 0)
            return false;
        ajax_return_status = 0;
        $.ajax({
            type : "POST",
            url:"{:U('Cart/pre_sell_cart')}",//+tab,
            data : $('#cart2_form').serialize()+"&act=submit_order",// 你的formid
            dataType: "json",
            success: function(data){

                if(data.status != '1')
                {
                    // 登录超时
                    if(data.status == -100) {
                        layer.open({
                            content: data.msg, time: 2, end: function () {
                                location.href ="{:U('Home/User/login')}";
                            }
                        });
                    }
                    showErrorMsg(data.msg);
                    return false;
                }
                layer.open({
                    content: '订单提交成功，跳转支付页面!', time: 2, end: function () {
                        location.href = "/index.php?m=Mobile&c=Cart&a=cart4&order_sn=" + data.result;
                    }
                });
            }
        });
    }

    $(function(){
        $('.submits_de').click(function(){
            $('.mask-filter-div').hide();
            $('.losepay').hide();
        })

        //显示隐藏使用发票信息
        $('.invoiceclickin').click(function(){
            $('#invoice').toggle(300);
        })
    })
</script>
</body>
</html>
